function CE(t) {
  return document.createElement(t);
}

var Slideshow = {
  pics: null,
  index: 0,
  img: null,
  counter: null,
  fullsizeLink: null,
  initialized: false,

  Init: function(pics, index) {
    if(!this.initialized) {
      this.pics = pics;
      this.index = index;
      this.img = $("#s_img");
      this.counter = $("#s_curr");
      this.fullsizeLink = $("#s_fullsize");
      this.counter.html(index + 1);
      $("#s_total").html(pics.length);
      $("#s_prev").mousedown(Slideshow.Prev);
      $("#s_next").mousedown(Slideshow.Next);
      this.img.mousedown(Slideshow.Click);
      $("#s_return").mousedown(Slideshow.ReturnToThumbnails);
    }

    this.setPic();
    $("#slideshow").css("display","block");
  },

  Click: function(e) {
    if(!e.shiftKey) {
      Slideshow.Next(e);
    }
    else {
      Slideshow.Prev(e);
    }
  },

  Next: function(e) {
    e.preventDefault()
    if(e.which!=1) { // Not the left button?
      return
    }
    var o = Slideshow;
    o.index = (++o.index) % o.pics.length;
    o.setPic();
  },

  Prev: function(e) {
    e.preventDefault()
    if(e.which!=1) {
      return
    }
    
    var o = Slideshow;
    if(o.index == 0) {
      o.index = o.pics.length;
    }
    o.index--;
    o.setPic();
  },

  setPic: function() {
    var i = this.index + 1;
    var p = this.pics[this.index];
    this.img.attr('src', picUrl + p.p + "/" + displaySubdir + "/" + p.n);
    this.fullsizeLink.attr('href', picUrl + p.p + "/" + p.n);
    this.counter.html(i);
  }
}